/*#include <iostream>
#include <vector>
using namespace std;

void mergeAndPrintLists(const vector<int> &S1, const vector<int> &S2)
{
    vector<int> S3;


    for (size_t i = 0; i < S1.size();i++)
    {
        for (size_t j = 0; j < S2.size(); j++)
            if (S1[i] == S2[j])
            {
                S3.push_back(S1[i]);
                j++;
            }
            else
            {

                j++;
            }
    }

        // 输出合并后的链表S3
    if (S3.empty())
    {
        cout << "NULL";
    }
    else
    {
        for (size_t k = 0; k < S3.size(); ++k)
        {
            cout << S3[k];
            if (k < S3.size() - 1)
            {
                cout << " ";
            }
        }
    }
}

int main()
{
    vector<int> S1, S2;
    int num;

    // 读取第一个非降序序列
    while (cin >> num && num != -1)
    {
        S1.push_back(num);
    }

    // 读取第二个非降序序列
    while (cin >> num && num != -1)
    {
        S2.push_back(num);
    }

    // 合并并打印结果
    mergeAndPrintLists(S1, S2);

    return 0;
}*/
#include <iostream>
#include <vector>

void mergeAndPrintLists(const std::vector<int> &S1, const std::vector<int> &S2)
{
    std::vector<int> S3;
    size_t i = 0, j = 0;

    // 使用双指针法合并两个序列
    while (i < S1.size() && j < S2.size())
    {
        if (S1[i] < S2[j])
        {
            S3.push_back(S1[i]);
            i++;
        }
        else
        {
            S3.push_back(S2[j]);
            j++;
        }
    }

    // 若S1还有剩余，添加到S3
    while (i < S1.size())
    {
        S3.push_back(S1[i]);
        i++;
    }

    // 若S2还有剩余，添加到S3
    while (j < S2.size())
    {
        S3.push_back(S2[j]);
        j++;
    }

    // 输出合并后的链表S3
    if (S3.empty())
    {
        std::cout << "NULL";
    }
    else
    {
        for (size_t k = 0; k < S3.size(); ++k)
        {
            std::cout << S3[k];
            if (k < S3.size() - 1)
            {
                std::cout << " ";
            }
        }
    }
}

int main()
{
    std::vector<int> S1, S2;
    int num;

    // 读取第一个非降序序列
    while (std::cin >> num && num != -1)
    {
        S1.push_back(num);
    }

    // 读取第二个非降序序列
    while (std::cin >> num && num != -1)
    {
        S2.push_back(num);
    }

    // 合并并打印结果
    mergeAndPrintLists(S1, S2);

    return 0;
}